package chap01;

import java.text.SimpleDateFormat;
import java.util.Date;

class DemoThread3 implements Runnable {
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    private boolean flag = true;

    @Override
    public void run() {
        while (flag) {
            System.out.println(sdf.format(new Date()));
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }
}
